[PATCH] src: rethrow stack overflow exceptions in async_hooks
authorMatteo Collina <hello@matteocollina.com>
Tue, 9 Dec 2025 22:50:18 +0000 (23:50 +0100)
committerJérémy Lal <kapouer@melix.org>
Tue, 24 Mar 2026 21:11:25 +0000 (22:11 +0100)
commit4afc5bfb18049c2938961950cadd5987e0a52212
tree4c0fa45728b9e6ded2e42523477d8f553614d5f1
parenta833ed5a23c44d4e48904a2e4364634f7a5edbf7
[PATCH] src: rethrow stack overflow exceptions in async_hooks

When a stack overflow exception occurs during async_hooks callbacks
(which use TryCatchScope::kFatal), detect the specific "Maximum call
stack size exceeded" RangeError and re-throw it instead of immediately
calling FatalException. This allows user code to catch the exception
with try-catch blocks instead of requiring uncaughtException handlers.

The implementation adds IsStackOverflowError() helper to detect stack
overflow RangeErrors and re-throws them in TryCatchScope destructor
instead of calling FatalException.

This fixes the issue where async_hooks would cause stack overflow
exceptions to exit with code 7 (kExceptionInFatalExceptionHandler)
instead of being catchable.

Fixes: https://github.com/nodejs/node/issues/37989
Ref: https://hackerone.com/reports/3456295
PR-URL: https://github.com/nodejs-private/node-private/pull/773
Refs: https://hackerone.com/reports/3456295
Reviewed-By: Robert Nagy <ronagy@icloud.com>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
CVE-ID: CVE-2025-59466

Gbp-Pq: Topic sec
Gbp-Pq: Name 37-rethrow-stack-overflow-exceptions-in-async-hooks.patch
src/async_wrap.cc
src/debug_utils.cc
src/node_errors.cc
src/node_errors.h
src/node_report.cc
test/parallel/test-async-hooks-stack-overflow-nested-async.js [new file with mode: 0644]
test/parallel/test-async-hooks-stack-overflow-try-catch.js [new file with mode: 0644]
test/parallel/test-async-hooks-stack-overflow.js [new file with mode: 0644]
test/parallel/test-uncaught-exception-handler-stack-overflow-on-stack-overflow.js [new file with mode: 0644]
test/parallel/test-uncaught-exception-handler-stack-overflow.js [new file with mode: 0644]